package com.yix.admin.modules.system.entity;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.yix.common.base.BaseUUIDEntity;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.CreationTimestamp;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Objects;
import java.util.Set;

/**
 * @author wdx
 * @version 1.0
 * @Description TODO
 * @date 2021/1/27 16:48
 */
@Entity
@Getter
@Setter
@Table(name = "sys_menu")
@org.hibernate.annotations.Table(appliesTo = "sys_menu",comment = "菜单表")
public class SysMenu extends BaseUUIDEntity implements Serializable {

    @JSONField(serialize = false)
    @ManyToMany(mappedBy = "menus")
    @ApiModelProperty(value = "菜单角色")
    private Set<SysRole> roles;

    @NotBlank
    @Column(columnDefinition = "varchar(255) COMMENT '名称'")
    @ApiModelProperty(value = "名称")
    private String name;

    @Column(columnDefinition = "int(11) COMMENT '排序'")
    @ApiModelProperty(value = "排序")
    private Integer menuSort = 999;

    @Column(columnDefinition = "varchar(255) COMMENT '链接地址'")
    @ApiModelProperty(value = "链接地址")
    private String path;

    @Column(columnDefinition = "varchar(255) COMMENT '组件'")
    @ApiModelProperty(value = "组件")
    private String component;

    @Column(columnDefinition = "varchar(255) COMMENT '组件名称'")
    @ApiModelProperty(value = "组件名称")
    private String componentName;

    @Column(columnDefinition = "int(11) COMMENT '菜单类型'")
    @ApiModelProperty(value = "菜单类型")
    private Integer type;

    @Column(columnDefinition = "varchar(255) COMMENT '权限'")
    @ApiModelProperty(value = "权限")
    private String permission;

    @Column(columnDefinition = "varchar(255) COMMENT '图标'")
    @ApiModelProperty(value = "图标")
    private String icon;

    @Column(columnDefinition = "bit(1) default 0 COMMENT '缓存'")
    @ApiModelProperty(value = "缓存")
    private Boolean cache;

    @Column(columnDefinition = "bit(1) default 0 COMMENT '隐藏'")
    @ApiModelProperty(value = "隐藏")
    private Boolean hidden;

    @ApiModelProperty(value = "子节点数目", hidden = true)
    private Integer subCount = 0;

    @Column(name = "pid",columnDefinition = "varchar(32) COMMENT '上级菜单ID'")
    @ApiModelProperty(value = "上级菜单ID")
    private String pid;

    @Column(columnDefinition = "bit(1) COMMENT '是否为外链'")
    @ApiModelProperty(value = "是否为外链")
    private Boolean iFrame;

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        SysMenu menu = (SysMenu) o;
        return Objects.equals(id, menu.id);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id);
    }
}
